package com.example.informationEntry.service.impl;

import com.example.informationEntry.dao.NaTuitionDao;
import com.example.informationEntry.entity.NaTuition;
import com.example.informationEntry.service.NaTuitionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学费表(NaTuition)表服务实现类
 *
 * @author makejava
 * @since 2019-04-08 11:20:34
 */
@Service("naTuitionService")
public class NaTuitionServiceImpl implements NaTuitionService {
    @Resource
    private NaTuitionDao naTuitionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param studentId 主键
     * @return 实例对象
     */
    @Override
    public NaTuition queryById(String studentId) {
        return this.naTuitionDao.queryById(studentId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<NaTuition> queryAllByLimit(int offset, int limit) {
        return this.naTuitionDao.queryAllByLimit(offset, limit);
    }

    /**
     * 查询多条数据
     *
     * @param naTuition 实例对象
     * @return list集合
     */
    @Override
    public List<NaTuition> queryAll(NaTuition naTuition){
        return this.naTuitionDao.queryAll(naTuition);
    }

    /**
     * 新增数据
     *
     * @param naTuition 实例对象
     * @return 实例对象
     */
    @Override
    public NaTuition insert(NaTuition naTuition) {
        this.naTuitionDao.insert(naTuition);
        return naTuition;
    }

    /**
     * 修改数据
     *
     * @param naTuition 实例对象
     * @return 实例对象
     */
    @Override
    public NaTuition update(NaTuition naTuition) {
        this.naTuitionDao.update(naTuition);
        return this.queryById(naTuition.getStudentNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param studentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String studentId) {
        return this.naTuitionDao.deleteById(studentId) > 0;
    }


    /**
     * 进行学费信息拼接
     *
     * @return
     */
    @Override
    public Map<String, Map<String ,Object>> queryNumberToName(){
        Map<String ,Map<String,Object>> resultMap = new HashMap<>();
        List<NaTuition> resultList = this.naTuitionDao.queryAll(new NaTuition());
        for (NaTuition tuition : resultList) {
            Map<String,Object> map = new HashMap<>();
            map.put("tuitionNumber",tuition.getTuitionNumber());
            map.put("discountInfNumber",tuition.getDiscountInfNumber());
            map.put("registeryFee",tuition.getRegisteryFee());
            map.put("tuitionPaid",tuition.getTuitionPaid());
            map.put("surplusTuition",tuition.getSurplusTuition());
            resultMap.put(tuition.getStudentNumber(),map);
        }
        return resultMap;
    }
}